package com.michael.retail.sys.biz.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONObject;
import com.michael.retail.commons.constant.AuthConstant;
import com.michael.retail.commons.pojo.global.R;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 类功能描述:
 * <pre>
 *   测试用
 * </pre>
 *
 * @author Michael
 * @version 1.0
 * @date 2021/7/15 10:08
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    @GetMapping("/say")
    public R hello(@RequestParam String name) {
        return R.succeed("hello " + name);
    }

    @GetMapping("/do")
    public R doHello(@RequestParam String name) {
        return R.succeed("do hello " + name);
    }

    @GetMapping("/user")
    public R user(HttpServletRequest request) {
        String userStr = request.getHeader(AuthConstant.JWT_PAYLOAD_KEY);
//        JSONObject userJsonObject = new JSONObject(userStr);
//        UserDTO userDTO = new UserDTO();
//        userDTO.setUsername(userJsonObject.getStr("user_name"));
//        userDTO.setId(Convert.toLong(userJsonObject.get("id")));
//        userDTO.setRoles(Convert.toList(String.class,userJsonObject.get("authorities")));
        return R.succeed(userStr);
    }
}
